import http from '@/util/request/index'
import { API_URL } from '@/env'

/**
 * 获取模板
 *  @param {Object} data
 * @param {String} data.app_id 小程序id
 * @param {'wx_applet'} data.channel 管理后台code
 * @returns {Promise<import('@/types/template').TemplateResponse>}
 */
export const getTemplate = (data) => {
  return http({
    url: 'frontend/product/decorate',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 获取门票列表
 * @param {Object} data
 * @param {Number} data.type
 * @param {String} data?.name
 * @param {String} data.admin_code
 * @param {String} data?.area_code
 * @returns {Promise<import('@/types/jsdoc').TicketsList>}
 */
export const getTickets = (data) => {
  return http({
    url: 'frontend/product/searchProduct',
    auth: false,
    method: 'get',
    data,
  })
}
/**
 * 获取所有门票列表
 * @param {Object} data
 * @param {Number} data.type
 * @param {String} data?.name
 * @param {String} data.admin_code
 * @param {String} data?.area_code
 * @returns {Promise<import('@/types/jsdoc').TicketsListAll>}
 */
export const getTicketsAll = (data) => {
  return http({
    url: 'frontend/product/searchProduct',
    auth: false,
    method: 'get',
    data: Object.assign(data, { limit: 'all' }),
  })
}
/**
 * 获取门票详情
 * @param {Object} data
 * @param {String} data.id
 * @param {String} data.admin_code
 * @returns {Promise<import('@/types/jsdoc').TicketsDetail>}
 */
export const getTicketsDetail = (data) => {
  return http({
    url: 'frontend/product/scenicDetail',
    auth: false,
    method: 'get',
    data,
  })
}
/**
 * @returns {Promise<import('@/types/lineTickets').LineTicketsResponse>}
 * */
export const getTicket = (data) => {
  return http({
    url: 'frontend/product/tickets',
    auth: false,
    method: 'get',
    data,
  })
}
export const getTicketCalendar = (data) => {
  return http({
    url: 'frontend/product/productCalendar',
    auth: false,
    method: 'get',
    data,
  })
}
export const SubmitPreOrder = (data) => {
  return http({
    url: 'applet/order/preOrder',
    auth: true,
    login: false,
    method: 'post',
    data,
  })
}
export const submitPay = (data) => {
  return http({
    url: 'applet/order/orderSubmit',
    auth: true,
    method: 'post',
    data,
  })
}
export const wxPay = (data) => {
  return http({
    url: 'applet/order/pay',
    auth: true,
    method: 'post',
    data,
  })
}

/**
 * 预约下单
 * @return {Promise<import('@/types/submit').SubmitResponse>}
 * */
export const seatSbmitPay = (data) => {
  return http({
    url: 'applet/order/orderSubmit',
    auth: true,
    method: 'post',
    data,
  })
}
/**
 * 零元支付
 * @param data
 * @returns {Promise<*>|*}
 */
export const zeroPay = (data) => {
  return http({
    url: 'applet/order/miniProgramPaySuccess',
    auth: true,
    method: 'post',
    data,
  })
}
export const defaultCity = (data) => {
  return http({
    url: 'frontend/product/defaultCitys',
    auth: false,
    method: 'get',
    data,
  })
}
export const getCategory = (admin_code) => {
  return http({
    url: `frontend/product/category?admin_code=${admin_code}&type=line`,
    auth: false,
    method: 'get',
  })
}
export const getFoodCategory = (admin_code) => {
  return http({
    url: `frontend/product/category?admin_code=${admin_code}&type=specialty`,
    auth: false,
    method: 'get',
  })
}
export const getCategorys = (admin_code,type) => {
  return http({
    url: `frontend/product/category?admin_code=${admin_code}&type=${type}`,
    auth: false,
    method: 'get',
  })
}
export const productInfo = (data) => {
  return http({
    url: 'frontend/product/productInfo/0',
    auth: false,
    method: 'get',
    data,
  })
}
export const foodRecommendScenic = (data) => {
  return http({
    url: 'frontend/scenic/recommendScenic',
    auth: false,
    method: 'get',
    data,
  })
}
export const specialRecommendScenic = (data) => {
  return http({
    url: 'frontend/scenic/productStore',
    auth: false,
    method: 'get',
    data,
  })
}
export const SubmitPay = (data) => {
  return http({
    url: 'applet/order/pay',
    auth: true,
    method: 'post',
    data,
  })
}

export const getOrderList = (data) => {
  return http({
    url: 'applet/order/list',
    auth: true,
    method: 'get',
    data,
  })
}
export const getOrderDetail = (data) => {
  return http({
    url: 'applet/order/detail',
    auth: true,
    method: 'get',
    data,
  })
}
export const orderAllDetail = (data) => {
  return http({
    url: 'applet/order/orderAllDetail',
    auth: true,
    method: 'get',
    data,
  })
}
export const subReceipt = (data) => {
  return http({
    url: 'applet/order/subReceipt',
    auth: true,
    method: 'get',
    data,
  })
}

export const getCodeApi = (data) => {
  return http({
    url: 'applet/order/consume-list',
    auth: true,
    method: 'get',
    data,
  })
}
export const refundApi = (data) => {
  return http({
    url: 'applet/order/ticketRefund',
    auth: true,
    method: 'post',
    data,
  })
}

/**
 * 添加联系人
 * @param {Object} data
 * @param {String|Number} data.user_id  用户id
 * @param {String} data.name  联系人姓名
 * @param {String} data.mobile  联系人手机号
 * @param {String} data.id_card  联系人身份证号
 */
export const setContacts = (data) => {
  return http({
    url: 'applet/user/setContacts',
    auth: true,
    method: 'post',
    data,
  })
}

/**
 * 获取联系人列表
 * @param {Object} data
 * @param {String|Number} data.user_id  用户id
 */
export const getContactsApi = (data) => {
  return http({
    url: 'applet/user/getContacts',
    auth: true,
    method: 'get',
    data,
  })
}

/**
 *
 * @param {Objectj} data
 * @param {String|Number} data.id  联系人id
 */
export const contactsDel = (data) => {
  return http({
    url: 'applet/product/getContacts',
    auth: false,
    method: 'delete',
    data,
  })
}

export const updateContacts = (data) => {
  return http({
    url: 'applet/user/updateContacts',
    auth: false,
    method: 'POST',
    data,
  })
}

/**
 *
 * @param {Object} data
 * @param {String} data.app_id  小程序id
 * @param {String} data.open_id  用户openid
 * @param {String} data.avatar  用户头像
 * @param {String} data.nickname  用户昵称
 * @param {String} data.channel 平台 app.globalData.platform
 * @param {String} data.mobile  用户手机号
 */
export const saveUserInfo = (data) => {
  return http({
    url: 'frontend/user/userInfo',
    auth: false,
    method: 'POST',
    data,
  })
}

/**
 * 获取推荐数据
 * @param {Object} data
 * @param {String} data.admin_code  code
 * @param {String} data.type  类型
 * @return {Promise<import('@/types/recommend').RecommendResponse>}
 */
export const recommendScenic = (data) => {
  return http({
    url: 'frontend/product/recommendScenic',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 获取热门文章
 * @param {Object} data
 * @param {String} data.admin_code  code
 */
export const recommendedArticle = (data) => {
  return http({
    url: 'frontend/product/recommendedArticle',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 添加阅读人数
 * @param {Object} data
 * @param {String} data.id  文章id
 * @param {String} data.open_id  用户openid
 *
 */
export const articleReadNum = (data) => {
  return http({
    url: 'frontend/product/articleReadNum',
    auth: false,
    method: 'post',
    data,
  })
}

/**
 * 获取文章详情
 * @param {Object} data
 * @param {String} data.id  文章id
 */
// @param {'strategy'|'essay'|'information'|'culture'} data.type 类型

export const recommendArticleDetail = (data) => {
  return http({
    url: `frontend/product/recommendArticleDetail?id=${data.id}`,
    auth: false,
    method: 'get',
  })
}

/**
 * 获取攻略列表、文章列表、资讯列表、非遗列表
 * @param {Object} data
 * @param {'strategy'|'essay'|'information'|'culture'|'play'} data.type strategy攻略 essay 文章 information 资讯  culture 非遗
 * @return {Promise<import('@/types/raiders').RaidersResponse>}
 */
export const strategyList = (data) => {
  return http({
    url: `frontend/product/strategy`,
    auth: false,
    method: 'get',
    data,
  })
}
export const cityIntro = (data) => {
  return http({
    url: `frontend/product/strategy`,
    auth: false,
    method: 'get',
    data,
  })
}

export const strategyDetail = (data) => {
  return http({
    url: `frontend/user/richText?id=${data.id}`,
    auth: false,
    method: 'get',
  })
}

/**
 *
 * @param {Object} data
 * @param {String} data.open_id  用户openid
 * @param {String} data.id  文章id
 * @param {'strategy'|'essay'|'information'|'culture'} data.type 类型 strategy攻略 essay 文章 information资讯  culture 非遗
 */
export const richTextReadNum = (data) => {
  return http({
    url: `frontend/product/richTextReadNum`,
    auth: false,
    method: 'post',
    data,
  })
}

/**
 * 出入境列表
 */
export const getBorderList = (data) => {
  return http({
    url: `applet/user/pointList`,
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 出入境提交预约
 * @param {Object} data
 * @param {String} data.user_id  用户id
 * @param {String} data.s_id  产品id
 * @param {String} data.name  姓名
 * @param {String} data.family_name  英文姓
 * @param {String} data.id_card  身份证号
 * @param {String} data.mobile  手机号
 * @param {1|2} data.type  类型 1出境 2入境
 */
export const submitBorder = (data) => {
  return http({
    url: `applet/user/recordAdd`,
    auth: false,
    method: 'post',
    data,
  })
}

/**
 *
 * @param {Object} data
 * @param {String} data.id_card  身份证号查找
 * @param {String} data.name  姓名
 * @param {String} data.created_at[min] 时间范围
 * @param {String} data.created_at[max] 时间范围
 * @returns
 */
export const recordList = (data) => {
  return http({
    url: `applet/user/recordList`,
    auth: false,
    method: 'get',
    data,
  })
}

export const getRescueInfo = (data) => {
  return http({
    url: `frontend/user/getRescueInfo`,
    auth: false,
    method: 'get',
    data,
  })
}

/**
 *获取天气
 * @return {Promise<import('@/types/weather').WeatherResponse>}
 */
export const getWeatherInfo = (data) => {
  return http({
    url: `frontend/user/weather`,
    auth: false,
    method: 'get',
    data,
  })
}
/**
 * 在线上传
 * @param {Object} data
 * @param {String} data.mobile  手机号
 * @param {String} data.content  内容
 * @param {Array} data.images  图片
 * @param {String} data.type  类型 1产品功能反馈 2建议与意见反馈 3投诉其它问题
 * @param {String} data.user_id 用户id
 * @param {string} data.user_name 用户名
 */
export const complaintSubmit = (data) => {
  return http({
    url: `applet/user/complaint`,
    auth: false,
    method: 'post',
    data,
  })
}

/**
 *上传图片
 *@param {Object} data
 @param {File} data.image  图片
 */
export const uploadImages = (data) => {
  return http({
    url: `upload/image`,
    auth: false,
    method: 'post',
    data,
  })
}

/**
 * 价格日历
 * @param {Object} data
 * @param {String} data.admin_code
 * @param {String} data.supplier_code
 * @param {String} data.product_id
 * @param {String} data.limit
 * @param {String} data.play_date
 * @returns {Promise<import('@/types/reserve').ReserveResponese>}
 */
export const priceCalendar = (data) => {
  return http({
    url: `frontend/product/productCalendar?query[admin_code]=${data.admin_code}&query[supplier_code]=${data.supplier_code}&query[product_id]=${data.product_id}&query[play_date]=${data.play_date}`,
    auth: false,
    method: 'get',
  })
}

/**
 * 逆地址解析
 * @param {Object} data
 * @param {String} data.lat
 * @param {String} data.lng
 */
export const getMapAddresss = (data) => {
  return http({
    url: `frontend/user/getMapAddress`,
    auth: false,
    method: 'post',
    data,
  })
}

export const addAddress = (data) => {
  return http({
    url: `applet/user/saveAddress`,
    auth: false,
    method: 'post',
    data,
  })
}
export const addressList = (data) => {
  return http({
    url: `applet/user/getAddress`,
    auth: false,
    method: 'get',
    data,
  })
}
export const addressDetail = (data) => {
  return http({
    url: `applet/user/getAddressDetail`,
    auth: false,
    method: 'get',
    data,
  })
}
export const removeAddress = (data) => {
  return http({
    url: `applet/user/removeAddress`,
    auth: false,
    method: 'delete',
    data,
  })
}
export const setDefaultAddress = (data) => {
  return http({
    url: `applet/user/setDefaultAddress`,
    auth: false,
    method: 'get',
    data,
  })
}

export const createSpecialtyOrder = (data) => {
  return http({
    url: `applet/order/createSpecialtyOrder`,
    auth: false,
    method: 'post',
    data,
  })
}

//applet/order/getUserExpress
export const logisticsInformation = (data) => {
  return http({
    url: `applet/order/getUserExpress`,
    auth: false,
    method: 'get',
    data,
  })
}

export const hideEntrance = (data) => {
  return http({
    url: `frontend/user/hideEntrance`,
    auth: false,
    method: 'get',
    data,
  })
}

/**特产退款 */
export const refundSpecialty = (data) => {
  return http({
    url: `applet/order/applyForAfterSales`,
    auth: false,
    method: 'post',
    data,
  })
}
//applet/order/afterSalesDetail
export const afterSalesDetail = (data) => {
  return http({
    url: `applet/order/afterSalesDetail`,
    auth: false,
    method: 'get',
    data,
  })
}

//收藏
export const addFavorite = (data) => {
  return http({
    url: `applet/user/addFavorite`,
    auth: false,
    method: 'post',
    data,
  })
}

/**
 * 收藏列表
 * @param {Object} data
 * @param {0|1} data.type
 * @return {Promise<import('@/types/collect').CollectResponse>}
 */
export const favoriteList = (data) => {
  return http({
    url: `applet/user/favoriteList`,
    auth: false,
    method: 'get',
    data,
  })
}

export const scenicReadNum = (data) => {
  return http({
    url: `frontend/product/scenicReadNum`,
    auth: false,
    method: 'post',
    data,
  })
}

/**
 * 获取热搜词
 * @param {Object} data
 * @param {'index'|'search'} data.type  index 首页 search搜索页
 * @return {Promise<import('@/types/hotKey').HotKeyResponse>}
 * */
export const hotKey = (data) => {
  return http({
    url: 'frontend/config/getRichSearch?limit=all',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 获取热搜词
 * @return {Promise<import('@/types/linefilter').LineFilterResponse>}
 * */
export const lineFilter = () => {
  return http({
    url: 'frontend/product/lineSift',
    auth: false,
    method: 'get',
  })
}

/**
 * 商家路线列表
 * @return {Promise<import('@/types/merchant').CorpResponse>}
 * */
export const adminCorp = (data) => {
  return http({
    url: 'frontend/product/getAdminCorp',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 分类
 * @param data
 * @param {String} data.admin_code jxfxs
 * @param {import('@/types/ticket-type').Category} data.type
 * @return {Promise<import('@/types/category').CateGoryResponse>}
 */
export const category = (data) => {
  return http({
    url: 'frontend/product/category',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 发现页轮播图
 * @param {Object} data
 * @param {'found'} data.type
 * @param {String} data.admin_code
 * */
export const foundBanner = (data) => {
  return http({
    url: 'frontend/user/banner',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 历史记录
 * @param {Object} data
 * @param {string} data.user_id
 * @param {'scenic'|'line'|'strategy'} data.type
 */
export const historyAdd = (data) => {
  return http({
    url: 'applet/user/historyAdd',
    auth: true,
    method: 'post',
    data,
  })
}

/**
 * 历史记录
 * @param {Object} data
 * @param {string} data.user_id
 * @param {'scenic'|'line'|'strategy'} data.type
 * @return {Promise<import('@/types/history').HistoryResponse>}
 */
export const historyList = (data) => {
  return http({
    url: 'applet/user/historyList',
    auth: false,
    method: 'get',
    data,
  })
}
export const aboutDetail = (data) => {
  return http({
    url: 'frontend/config/detail',
    auth: false,
    method: 'get',
    data,
  })
}

export const cardList = (data) => {
  return http({
    url: 'applet/user/cardList',
    auth: false,
    method: 'get',
    data,
  })
}

export const getAdminCorpList = (data) => {
  return http({
    url: 'frontend/config/getAdminCorpList',
    auth: false,
    method: 'get',
    data,
  })
}

/*获取公厕*/
export const getLavatory = (data) => {
  return http({
    url: 'frontend/user/lavatory',
    auth: false,
    method: 'get',
    data,
  })
}

export const liveDetail = (data) => {
  return http({
    url: 'frontend/config/getScenicLink',
    auth: false,
    method: 'get',
    data,
  })
}
/**
 * 慢直播列表
 * @param data
 * @returns {Promise<import('@/types/live').LiveResponse>}
 */
export const liveList = (data) => {
  return http({
    url: 'frontend/config/getScenicLinkList',
    auth: false,
    method: 'get',
    data,
  })
}
/**
 * 抠图
 * @param data
 * @param {File } data.image
 * @returns {Promise<*>|*}
 */
export const ClipImage = (data) => {
  return http({
    url: 'applet/user/userPhotoCutout',
    auth: false,
    method: 'post',
    data,
  })
}

/**
 * 慢直播
 * @param data
 * @param {'live_room_url' | 'vr_map_url' | 'hand_map_url'} data.type
 * @return {Promise<import('@/types/live-move').LiveMoveResponse>}
 * @constructor
 */
export const LiveList = (data) => {
  return http({
    url: 'frontend/scenic/scenicLink',
    auth: false,
    method: 'get',
    data,
  })
}
export const createUserLine = (data) => {
  return http({
    url: 'applet/user/createUserLine',
    auth: false,
    method: 'post',
    data,
  })
}
/**
 * 穿衣指数
 * @param data
 * @param {Number} data.scenic_id 景区id
 * @param {Number} data.city 城市id
 * @returns {Promise<*>|*}
 */
export const DressingIndex = (data) => {
  return http({
    url: 'frontend/user/indices',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 场馆场次
 * @param data
 * @param {Number} data.scenic_id 景区id
 * @param {Number} data.limit 分页
 * @return {Promise<import('@/types/theaterSession').TheaterSessionResponse>}
 */
export const getTheaterSession = (data) => {
  return http({
    url: 'frontend/product/theaterSession',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 场馆座位
 * @param data
 * @param {number} data.scenic_id 景区id
 * @param {string|number} data.play_date 游玩日期
 * @param {string|number} data.theater_session_id 剧场场次
 * @param {string|number} data.theater_area_group_id 剧场区域
 */
export const getSeat = (data) => {
  return http({
    url: 'frontend/product/theater-seat-occupy',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 剧场票价
 * @param data
 * @param {number} data.theater_session_id 景区id
 */
export const theaterProductPrice = (data) => {
  return http({
    url: 'frontend/product/theaterProductPrice',
    auth: false,
    method: 'get',
    data,
  })
}

/**
 * 提交表单
 */
export const visitorSubmit = (data) => {
  return http({
    url: 'applet/user/addVisitor',
    auth: true,
    method: 'post',
    data,
  })
}

export const vistorList = (data) => {
  return http({
    url: 'applet/user/getVisitorList',
    auth: true,
    method: 'get',
    data,
  })
}

/**
 * 上传图片
 * */
export function uploadFilePromise(file) {
  uni.showLoading({
    title: '上传中',
    mask: true,
  })
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: API_URL + 'upload/image',
      filePath: file,
      name: 'image',
      success: (e) => {
        resolve(JSON.parse(e.data))
      },
      fail: (e) => {
        reject(JSON.parse(e))
      },
      complete: () => {
        uni.hideLoading()
      },
    })
  })
}

//加油站供应商信息
export const getSupplier = (data) => {
  return http({
    url: 'frontend/scenic/getSupplier',
    auth: false,
    login: false,
    method: 'get',
    data,
  })
}
export const gasSubmit = (data) => {
  return http({
    url: 'applet/order/gasSubmit',
    auth: true,
    method: 'post',
    data,
  })
}
export const bingMobile = (data) => {
  return http({
    url: 'frontend/user/bindMobile',
    auth: false,
    method: 'post',
    data,
  })
}
export const locationList = (data) => {
  return http({
    url: 'frontend/newHotel/areaList',
    auth: false,
    method: 'get',
    data,
  })
}
export const hotelList = (data) => {
  return http({
    url: 'frontend/newHotel/list',
    auth: false,
    method: 'get',
    data,
  })
}
export const hotelNewDetail = (data) => {
  return http({
    url: 'frontend/newHotel/detail',
    auth: false,
    method: 'get',
    data,
  })
}
export const scenicUrlLink = (data) => {
  return http({
    url: 'frontend/scenic/scenicUrlLink',
    auth: false,
    method: 'get',
    data,
  })
}
export const swiperList = (data) => {
  return http({
    url: 'frontend/user/banner',
    auth: false,
    method: 'get',
    data,
  })
}
export const swiperDetail = (data) => {
  return http({
    url: 'frontend/user/bannerDetail',
    auth: false,
    method: 'get',
    data,
  })
}
export const videoList = (data) => {
  return http({
    url: 'frontend/config/videoList',
    auth: false,
    method: 'get',
    data,
  })
}
export const recentScenic = (data) => {
  return http({
    url: 'frontend/scenic/recentScenic',
    auth: false,
    method: 'get',
    data,
  })
}
export const getAreaCarMobile = (data) => {
  return http({
    url: 'frontend/scenic/getAreaCarMobile',
    auth: false,
    method: 'get',
    data,
  })
}
export const getCarCorpList = (data) => {
  return http({
    url: 'frontend/scenic/getCarCorpList',
    auth: false,
    method: 'get',
    data,
  })
}
export const getTrafficName = (data) => {
  return http({
    url: 'frontend/scenic/getTrafficName',
    auth: false,
    method: 'get',
    data,
  })
}

export const getTraffic = (data) => {
  return http({
    url: 'frontend/scenic/traffic',
    auth: false,
    method: 'get',
    data,
  })
}
export const getHotTraffic = (data) => {
  return http({
    url: 'frontend/scenic/hotTraffic',
    auth: false,
    method: 'get',
    data,
  })
}
export const configList = (data) => {
  return http({
    url: 'frontend/config/list',
    auth: false,
    method: 'get',
    data,
  })
}
